package com.ph.irp.base.assistantmaterial.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.ph.irp.base.assistantmaterial.dao.PBaseAssistantmaterialCustomerTypeDAO;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialCustomerTypeService;
import com.ph.irp.model.PBaseAssistantmaterialCustomercategory;

public class PBaseAssistantmaterialCustomerTypeServiceImpl implements
		PBaseAssistantmaterialCustomerTypeService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6015580155776711172L;
	private PBaseAssistantmaterialCustomerTypeDAO customerTypeDAOProxy ;
		
	/**
	 * 新增客户类别
	 */
	
	public void addCustomerType(
			PBaseAssistantmaterialCustomercategory customerTypeModel)  throws Throwable{
		
			customerTypeDAOProxy.addCustomerType(customerTypeModel) ;
	
	}
	/**
	 * 根据id删除客户类别
	 */
	@Override
	public void deleteProductpurposeById(String[] customerTypeIds) throws Throwable{
		for(String customerTypeId : customerTypeIds)
			customerTypeDAOProxy.deleteCustomer(customerTypeId) ;
		
	}
	
	/**
	 * 根据客户类别id查询客户类别
	 */
	@Override
	public PBaseAssistantmaterialCustomercategory getCustomerTypeById(
			Integer customerTypeId) throws Throwable{
		// TODO Auto-generated method stub
		PBaseAssistantmaterialCustomercategory customerTypeModel =null ;
		
		try {
			customerTypeModel = customerTypeDAOProxy.getCustomerTypeById(customerTypeId) ;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new Throwable("查询客户类别失败，请重试!");
		}
		
		return customerTypeModel;
	}
	
	/**
	 * 修改客户类别
	 */
	@Override
	public void updateCustomerType(
			PBaseAssistantmaterialCustomercategory customerTypeModel) throws Throwable{
		// TODO Auto-generated method stub
		
		try {
			customerTypeDAOProxy.updateCustomerType(customerTypeModel);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new Throwable("修改客户类别失败，请重试!");
		}
	
	}
	
	
	
	@Override
	public List<PBaseAssistantmaterialCustomercategory> getAllCustomerTypes()
			throws Throwable {
		return customerTypeDAOProxy.getAllCustomercategorys();
	}
	@Override
	public List<PBaseAssistantmaterialCustomercategory> getCustomerTypesByCode(String customerTypeCode)
			throws Throwable {
		return customerTypeDAOProxy.getCustomerTypeByCode(customerTypeCode);
	}
	@Override
	public List<PBaseAssistantmaterialCustomercategory> getCustomerTypesByCodeAndName(String customerTypeCode, String customerTypeName)
			throws Throwable {
		return customerTypeDAOProxy.getCustomerTypeByNameAndCode(customerTypeName, customerTypeCode);
	}
	@Override
	public List<PBaseAssistantmaterialCustomercategory> getCustomerTypesByName(String customerTypeName)
			throws Throwable {
		return customerTypeDAOProxy.getCustomerTypeByName(customerTypeName);
	}
	/**
	 * 动态查询客户类别
	 *//*
	@Override
	public List<PBaseAssistantmaterialCustomercategory> getCustomercategorys(PBaseAssistantmaterialCustomercategory customerTypeModel) throws Throwable{
		// TODO Auto-generated method stub
		//客户分类list
		List<PBaseAssistantmaterialCustomercategory>  customerTypeList = null ;
		
		//如果customerTypeModel为null
		if(customerTypeModel==null){
			try {
				customerTypeList = customerTypeDAOProxy.getAllCustomercategorys() ;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				throw new Throwable("查询客户类别失败，请重试!");
			}
		}
		else{//customerTypeModel不为null
			//客户类别name
			String name = customerTypeModel.getCustomerCategoryName() ;
			//客户类别code
			String code = customerTypeModel.getCustomerCategoryCode() ;
			if(!name.equals("")&&!code.equals("")){
				try {
					customerTypeList = customerTypeDAOProxy.getCustomerTypeByNameAndCode(name, code) ;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					throw new Throwable("查询客户类别失败，请重试!");
				}
			}
			else if(!name.equals("")){
				try {
					customerTypeList = customerTypeDAOProxy.getCustomerTypeByName(name) ;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					throw new Throwable("查询客户类别失败，请重试!");
				}
			}
			else if(!code.equals("")){
				try {
					customerTypeList = customerTypeDAOProxy.getCustomerTypeByCode(code) ;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					throw new Throwable("查询客户类别失败，请重试!");
				}
			} else
				try {
					customerTypeList = customerTypeDAOProxy.getAllCustomercategorys() ;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					throw new Throwable("查询客户类别失败，请重试!");
				}
		}
		return customerTypeList;
	}*/
	
	public PBaseAssistantmaterialCustomerTypeDAO getCustomerTypeDAOProxy() {
		return customerTypeDAOProxy;
	}
	
	public void setCustomerTypeDAOProxy(
			PBaseAssistantmaterialCustomerTypeDAO customerTypeDAOProxy) {
		this.customerTypeDAOProxy = customerTypeDAOProxy;
	}	
		
}
